package com.vadmin.vadminjava.common;

import java.io.InputStreamReader;
import java.util.Properties;

public class PropertiesUtil {

    private static Properties properties;
    private static final String name = "project-config.properties";

    static {
        try {
            properties = new Properties();
            properties.load(new InputStreamReader(PropertiesUtil.class.getClassLoader().getResourceAsStream(name), "utf-8"));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static String getValue(String key) {
        try {
            String value = properties.getProperty(key);
            return value.trim();
        } catch (Exception e) {
            return "";
        }
    }

    public static String getValue(String key, String defaultvalue) {
        String value = properties.getProperty(key);
        if (value == null) {
            value = defaultvalue;
        }
        return value.trim();
    }

    public static int getIntValue(String key, int defaultvalue) {

        int value = 0;
        try {

            value = Integer.parseInt(properties.getProperty(key).trim());
        } catch (Exception e) {
            value = defaultvalue;
        }

        return value;
    }
}
